package org.example.judge_contest.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.example.judge_common.rank.AllUserRank;
import org.example.judge_pojo.ContestRecord;

import java.util.List;

public interface ContestRecordMapper extends BaseMapper<ContestRecord> {

    /**
     * 用户提交通过总数
     * @param begin
     * @param end
     * @param beginTime 开始统计的时间
     * @return
     */
    @Select("SELECT user_id,count(DISTINCT problem_id) as accept_sum FROM `tb_contest_record` " +
            "where is_ac = 0 and status = 0 and create_time >= #{beginTime} GROUP BY user_id ORDER BY accept_sum desc limit #{begin},#{end}")
    List<AllUserRank> getAllRank(int begin, int end,String beginTime);

    /**
     * 该题目通过的名次
     * @param contestId
     * @param problemId
     * @return
     */
    @Select("select count(distinct user_id) from `tb_contest_record` " +
            "where contest_id = #{contestId} and problem_id = #{problemId} and is_ac = 0")
    Integer getAcceptProblemRank(String contestId,String problemId);

}
